define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer','fast'], function ($, undefined, Backend, Table, Form,Layer,Fast) {
        var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'crm/highseas/index',
                    add_url: 'crm/highseas/add',
                    edit_url: 'crm/highseas/edit',
                    del_url: 'crm/highseas/del',
                    multi_url: 'crm/highseas/multi',
                    table: 'highseas',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                pageSize: 10,
                pageList: [10,20],
                columns: [
                    [
                        {checkbox: true},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'buser.username', title: __('Buser.username'),operate:'LIKE'},
                        {field: 'buser.contacts', title: __('Buser.contacts'),operate:'LIKE'},
                        {field: 'buser.qq', title: __('Buser.qq'),operate:false},
                        {field: 'buser.wechat', title: __('Buser.wechat'),operate:false},
                        {field: 'buser.mobile', title: __('Buser.mobile'),operate:false},
                        {field: 'buser.email', title: __('Buser.email'),operate:false},
                        {field: 'product.product', title: __('Product.product'),operate:'LIKE'},
                        {field: 'admin.nickname', title: __('Admin.nickname'),operate:false},
                        /*{field: 'allot.followuptime', title: __('Allot.followuptime'), operate:'RANGE', addclass:'datetimerange'},*/
                        {field: 'reason', title: __('Reason'),operate:false},
                        {field: 'allot.status', title: __('Allot.status'), searchList: {"0":__('Allot.status 0'),"1":__('Allot.status 1'),"2":__('Allot.status 2'),"3":__('Allot.status 3'),"4":__('Allot.status 4'),"5":__('Allot.status 5')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                //审核过的数据和不是销售人员隐藏编辑按钮
                                $(table).data("operate-edit", null);
                                $(table).data("operate-del", null);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            },
                            buttons:[
                                {
                                    name: '公海挑入',
                                    text: __('公海挑入'),
                                    title: __('公海挑入'),
                                    extend:'title="公海挑入"',
                                    classname: 'btn btn-xs btn-primary btn-ajax btn-warning',
                                    icon: 'fa fa-pencil-square-o',
                                    confirm:'确认将客户从公海挑入？',
                                    url: 'crm/highseas/pick',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.type=='show'){
                                            return true;
                                        }else {
                                            return false;
                                        }
                                    },success:function (success,data) {
                                        if(data.code==1){
                                            //成功
                                            Layer.alert(data.msg);
                                            $(".btn-refresh").trigger("click");
                                        }else {
                                            //失败
                                            Layer.alert(data.msg);
                                        }
                                    },error:function (error,success) {
                                        /*Layer.msg('网络已断');*/
                                    }
                                },{
                                    name: '跟进记录',
                                    text: __('跟进记录'),
                                    title: __('跟进记录'),
                                    extend:'title="跟进记录"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-danger',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/buserfolloe/index/type/3',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });
            /**
             * 状态查询
             */
            $('.panel-heading a[data-toggle="tab"]').on('click',function () {
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;//初始化分页
            })
            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});